package com.pengli.mytools.utils.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

public class JsoupUtil {


    //获取网页头信息
    public static String getUrlIcon(String URL){

        try {
            Document doc = Jsoup.connect(URL).get();
            Element head = doc.head();
            String title = head.getElementsByTag("title").text();
            Elements link2 = head.select("link[rel='shortcut icon']");
            if (link2!=null) {
                for (Element element : link2) {
                    return element.attr("href");
                }
            }
            Elements link = head.select("link[rel='icon']");
            if (link!=null) {
                for (Element element : link) {
                    return element.attr("href");
                }
            }



        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;

    }
}
